﻿using DataScripter.Containers;
using DataScripter.Database;
using DataScripter.Database.SqlServer;

namespace DataScripter.Scripting.InputSources
{
    public class SqlServerInputSource : ChildContainer, ISqlServerInputSource
    {
        public SqlServerInputSource(string name, IContainer parent)
            : base(name, parent)
        { }

        protected override void OnInitialize()
        {
            if (!HasRegistration<IDatabaseStructure>())
            {
                RegisterType<IDatabaseStructure>("DatabaseStructure", typeof(SqlServerDatabaseStructure));
            }
            if (!HasRegistration<SqlServerDb>())
            {
                Db = new SqlServerDb(this);
                RegisterType(Db);
            }
            else
            {
                Db = Resolve<SqlServerDb>();
            }
        }


        public string ConnectionString { get; set; }
        public SqlServerDb Db { get; private set; }

        public ISqlServerStatementCreator StatementCreator
        {
            get { return new SqlServerStatementCreator(); }
        }
    }
}
